-
Notifications
You must be signed in to change notification settings - Fork 93
feat: Add singleton tables (empty primary keys) #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements support for singleton tables - tables with empty primary keys that can hold at most one row. This feature was described in the 2018 DataJoint paper and proposed in issue #113. Syntax: ```python @Schema class Config(dj.Lookup): definition = """ --- setting : varchar(100) """ ``` Implementation uses a hidden `_singleton` attribute of type `bool` as the primary key. This attribute is automatically created and excluded from user-facing operations (heading.attributes, fetch, join matching). Closes #113 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
dimitri-yatsenko
added a commit
to datajoint/datajoint-docs
that referenced
this pull request
Jan 22, 2026
- Add section 2.5 "Singleton Tables (Empty Primary Keys)" to table-declaration.md - Update university tutorial with CurrentTerm singleton example - Remove deprecated `___` separator mention (only `---` is supported) Related to datajoint/datajoint-python#1341 Closes datajoint/datajoint-python#113 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3 tasks
Add boolean_true_literal adapter property to generate correct DEFAULT value for the hidden _singleton attribute: - MySQL: DEFAULT 1 (bool maps to tinyint) - PostgreSQL: DEFAULT TRUE (native boolean) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Updated translate_attribute() to accept optional adapter parameter - PostgreSQL adapter's json_path_expr() now handles array notation and type casting - Pass adapter to translate_attribute() in condition.py, declare.py, expression.py This enables basic JSON operations to work on both MySQL and PostgreSQL. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MySQL accepts TRUE as a boolean literal (alias for 1), so we can use TRUE universally instead of having backend-specific literals. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MilagrosMarin
approved these changes
Jan 23, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements support for singleton tables — tables with empty primary keys that can hold at most one row. This feature was described in the 2018 DataJoint paper and proposed in #113.
Syntax
A definition with no attributes before
---creates a singleton table.Implementation
_singletonattribute of typeboolas the primary keyDEFAULT TRUEheading.attributes,fetch()results, and join matchingheading.primary_keyreturns[](empty)Changed Files
src/datajoint/declare.py- Singleton table creation logicsrc/datajoint/adapters/base.py- Addboolean_true_literalpropertysrc/datajoint/adapters/postgres.py- PostgreSQL-specific boolean literaltests/integration/test_declare.py- Comprehensive test coverageBehavior
_singleton=TrueDuplicateErrorfetch1()_singleton)heading.primary_key[](empty visible PK)Use Cases
Test Plan
test_singleton_declaration- Table creates with hidden_singletonattributetest_singleton_insert_and_fetch- Insert/fetch work without specifying keytest_singleton_uniqueness- Second insert raisesDuplicateErrortest_singleton_with_multiple_attributes- Works with multiple secondary attrstest_singleton_describe- Describe shows singleton natureCloses #113
🤖 Generated with Claude Code